package com.ywjt.platformbusiness.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.base.BaseCenterDialog;
import com.ywjt.platformbusiness.util.ToastUtil;


public class CenterAddNewTypeDialog extends Dialog {
    private EditText etContent;
    private TextView tvSure;
    private String typeName="";
    private Context context;


    private ClickListenerInterface clickListenerInterface;

    public interface ClickListenerInterface {
        void sure(String typename);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bindView();
    }

    public CenterAddNewTypeDialog(@NonNull Context context) {
        super(context);
        this.context = context;
    }

    public void bindView() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.edit_addtype_dialog);
        etContent=findViewById(R.id.etContent);
        tvSure=findViewById(R.id.tvSure);
        tvSure.setOnClickListener(new clickListener());
        etContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                typeName=s.toString().trim();
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

    }

    public void setClicklistener(ClickListenerInterface clickListener) {
        clickListenerInterface = clickListener;
    }

    private class clickListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.tvSure:
                    if (typeName.equals("")){
                        Toast.makeText(context, "新建分类名称不能为空", Toast.LENGTH_SHORT).show();
                    }else {
                        clickListenerInterface.sure(typeName);
                        dismiss();
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
